package com.jason.mvc.controller;

import com.jason.mvc.annoation.Autowired;
import com.jason.mvc.annoation.Controller;
import com.jason.mvc.annoation.RequestMapping;
import com.jason.mvc.annoation.Security;
import com.jason.mvc.service.UserService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("/user")
@Security({"zhangsan", "wangwu"})
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/findName")
    @Security({"zhangsan", "jason"})
    public void findUserName(HttpServletRequest request, HttpServletResponse response, String name) {
        String userName = userService.getUserName(name);
        System.out.println(userName);
        try {
            response.getWriter().println("访问成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/addUser")
    public void addUser(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("添加用户成功");
        try {
            response.getWriter().println("访问成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
